package com.joinway.framework.data.jdbc.bean;

import java.util.List;

import org.jsondoc.core.annotation.ApiObject;
import org.jsondoc.core.annotation.ApiObjectField;

import com.joinway.framework.bean.BaseBean;
import com.joinway.framework.bean.domain.constant.SqlConstants;
import com.joinway.framework.extension.groovy.DBConverter;

@ApiObject(name = "QueryCriteria", description = "", show=false)
public class Criteria extends BaseBean {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@ApiObjectField(description="true-当转换数据库列名时，转换为小写;false-转换为大写，默认true",required=false) 
	private boolean lowerCase = true;
	
	@ApiObjectField(description="true-表名或字段名不需要转换;false-表名或字段名需要转换成数据库列名，默认false",required=false) 
	private boolean rawName = false;
	
	@ApiObjectField(description="表名") 
	private String table;
	
	@ApiObjectField(description="全局查询条件连接关键字，如果未在字段中未指定查询条件，使用此条件，默认为and",required=false,format="and,or") 
	private String condition = SqlConstants.Condition.And;
	
	@ApiObjectField(description="查询条件",required=false) 
	private List<ConditionItem> items;
	
	@ApiObjectField(description="数据库类型，默认为mysql",required=false) 
	private String dbType = SqlConstants.DataBase.MySql;
	
	public String getTable(){
		return SqlConstants.DataBase.MySql.equalsIgnoreCase(dbType) ? DBConverter.escapeColumnName(table) : table;
	}

	public boolean isLowerCase() {
		return lowerCase;
	}

	public void setLowerCase(boolean lowerCase) {
		this.lowerCase = lowerCase;
	}

	public boolean isRawName() {
		return rawName;
	}

	public void setRawName(boolean rawName) {
		this.rawName = rawName;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public List<ConditionItem> getItems() {
		return items;
	}

	public void setItems(List<ConditionItem> items) {
		this.items = items;
	}

	public String getDbType() {
		return dbType;
	}

	public void setDbType(String dbType) {
		this.dbType = dbType;
	}

	public void setTable(String table) {
		this.table = table;
	}
}
